package org.example;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Properties;

public class MyApp {
    public static Object obj;
    public static Class cls;
    //private string
    public  static boolean create(String property_path) throws Exception{
        Properties props=new Properties();
        //读取配置文件
        InputStream input= MyApp.class.getClassLoader().getResourceAsStream(property_path);
        props.load(input);
        //创建对象
        String classname=props.getProperty("bootstrapClass");
        cls=Class.forName(classname);
        obj=cls.newInstance();
        input.close();
        return true;
    }
    //调用有注解的方法
    public static boolean call(Class cls,Object obj,String str) throws Exception{
        if(str==null){
            System.out.println("注解方法参数为空");
            throw new IllegalArgumentException();
        }
        Method[] methods = cls.getDeclaredMethods();
        for(Method mt:methods){
            if(mt.isAnnotationPresent(InitMethod.class)){
                mt.invoke(obj,str);
            }
        }
        return true;
    }
}

